<template>
  <div style="padding: 20px">
    <el-row>
      <el-col :span="8">
        <div style="display: flex;align-items: center;margin-bottom: 10px">
          <span style="flex: 0 0 auto;margin-right: 10px">标题:</span>
          <el-input v-model="queryParam.title" clearable></el-input>
        </div>
      </el-col>
      <el-col :span="8">
        <div style="display: flex;align-items: center;margin-bottom: 10px;">
          <el-button type="primary" size="small" style="margin-left: 10px" @click="handlerSearch">查询</el-button>
          <el-button type="primary" size="small" @click="handlerAdd">添加</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-table
          :data="tableData"
          style="width: 100%"
        >
          <el-table-column
            prop="id"
            label="序号"
          >
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            prop="title"
            label="标题"
          >
            <template #default="{row}">
              <div class="cursor-pointer" @click="handlerToDetail(row)">{{ row.title }}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="下载"
          >
            <template #default="{row}">
              <div>
                <a :href="row.docFile" class="px-2">下载文字版</a>
                <a :href="row.pdfFile" class="px-2">下载图片版</a>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" width="150">
            <template #default="{row}">
              <el-button type="danger" size="mini" @click="handlerDel(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="24" class="mt-2 flex justify-center">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParam.pageNum"
          :page-sizes="[5,10,20]"
          :page-size="queryParam.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import api from '@/api/users'

export default {
  name: 'index',
  data() {
    return {
      total: 0,
      tableData: [],
      queryParam: {
        pageSize: 2,
        pageNum: 1
      }
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    handlerAdd(){
      this.$router.push("/apply/guizhang/add")
    },
    handlerSearch() {
      this.queryParam.pageNum = 1
      this.fetchData()
    },
    handlerDel(row) {
      api.gui_zhang_List_delete(row.id).then(() => {
        this.$notify.success({
          title: '提示',
          message: '操作成功'
        })
        this.fetchData()
      })
    },
    handlerToDetail(row) {
      this.$router.push(`/apply/guizhang/detail?id=${row.id}`)
    },
    async fetchData() {
      let { data } = await api.gui_zhang_List(this.queryParam)
      console.log('>>>>>>>>>>>data', data)
      this.tableData = data.records
      this.total = data.total
    },
    handleCurrentChange(size) {
      this.queryParam.pageNum = size
      this.fetchData()
    },
    handleSizeChange(size) {
      this.queryParam.pageSize = size
      this.fetchData()
    }
  }
}
</script>
<style scoped>

</style>
